<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TikTok Spider API 文档</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            line-height: 1.6;
            color: #333;
            background-color: #f8f9fa;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 2rem;
            border-radius: 10px;
            margin-bottom: 2rem;
            text-align: center;
        }
        
        .header h1 {
            font-size: 2.5rem;
            margin-bottom: 0.5rem;
        }
        
        .header p {
            font-size: 1.1rem;
            opacity: 0.9;
        }
        
        .sidebar {
            position: fixed;
            left: 0;
            top: 0;
            width: 280px;
            height: 100vh;
            background: #2c3e50;
            color: white;
            overflow-y: auto;
            padding: 1rem;
            z-index: 1000;
        }
        
        .sidebar h3 {
            margin-bottom: 1rem;
            color: #ecf0f1;
        }
        
        .sidebar ul {
            list-style: none;
        }
        
        .sidebar li {
            margin-bottom: 0.5rem;
        }
        
        .sidebar a {
            color: #bdc3c7;
            text-decoration: none;
            padding: 0.5rem;
            display: block;
            border-radius: 5px;
            transition: background-color 0.3s;
        }
        
        .sidebar a:hover {
            background-color: #34495e;
            color: white;
        }
        
        .content {
            margin-left: 300px;
            padding: 1rem;
        }
        
        .api-section {
            background: white;
            border-radius: 10px;
            margin-bottom: 2rem;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        
        .api-header {
            padding: 1.5rem;
            border-bottom: 1px solid #eee;
        }
        
        .api-title {
            font-size: 1.5rem;
            margin-bottom: 0.5rem;
            color: #2c3e50;
        }
        
        .api-method {
            display: inline-block;
            padding: 0.3rem 0.8rem;
            border-radius: 20px;
            color: white;
            font-size: 0.9rem;
            font-weight: bold;
            margin-right: 1rem;
        }
        
        .method-get { background-color: #28a745; }
        .method-post { background-color: #007bff; }
        .method-put { background-color: #ffc107; color: #333; }
        .method-delete { background-color: #dc3545; }
        
        .api-url {
            font-family: 'Courier New', monospace;
            background-color: #f8f9fa;
            padding: 0.5rem;
            border-radius: 5px;
            margin: 0.5rem 0;
            font-size: 1.1rem;
        }
        
        .api-body {
            padding: 1.5rem;
        }
        
        .api-description {
            margin-bottom: 1.5rem;
            color: #666;
        }
        
        .params-table {
            width: 100%;
            border-collapse: collapse;
            margin: 1rem 0;
        }
        
        .params-table th,
        .params-table td {
            border: 1px solid #ddd;
            padding: 0.8rem;
            text-align: left;
        }
        
        .params-table th {
            background-color: #f8f9fa;
            font-weight: 600;
        }
        
        .code-block {
            background-color: #f8f9fa;
            border: 1px solid #e9ecef;
            border-radius: 5px;
            padding: 1rem;
            margin: 1rem 0;
            overflow-x: auto;
        }
        
        .code-block pre {
            margin: 0;
            font-family: 'Courier New', monospace;
            font-size: 0.9rem;
        }
        
        .response-example {
            background-color: #e8f5e8;
            border-left: 4px solid #28a745;
            padding: 1rem;
            margin: 1rem 0;
        }
        
        .error-example {
            background-color: #f8e8e8;
            border-left: 4px solid #dc3545;
            padding: 1rem;
            margin: 1rem 0;
        }
        
        .tag {
            display: inline-block;
            background-color: #6c757d;
            color: white;
            padding: 0.2rem 0.5rem;
            border-radius: 10px;
            font-size: 0.8rem;
            margin-right: 0.5rem;
        }
        
        .required {
            color: #dc3545;
            font-weight: bold;
        }
        
        .optional {
            color: #28a745;
        }
        
        @media (max-width: 768px) {
            .sidebar {
                display: none;
            }
            
            .content {
                margin-left: 0;
            }
        }
    </style>
</head>
<body>
    <div class="sidebar">
        <h3>📚 API 文档导航</h3>
        <ul>
            <li><a href="#overview">📋 概述</a></li>
            <li><a href="#auth">🔐 认证配置</a></li>
            <li><a href="#products">📦 商品管理</a></li>
            <li><a href="#scrapers">🕷️ 爬虫测试</a></li>
            <li><a href="#shoplus">🔍 Shoplus 集成</a></li>
            <li><a href="#videos">📹 视频数据</a></li>
            <li><a href="#complete-flow">🔄 完整流程</a></li>
            <li><a href="#config">⚙️ 配置管理</a></li>
        </ul>
    </div>

    <div class="content">
        <div class="header">
            <h1>🕷️ TikTok Spider API 文档</h1>
            <p>TikTok商品数据爬取与分析系统的完整API接口文档</p>
        </div>

        <div id="overview" class="api-section">
            <div class="api-header">
                <h2 class="api-title">📋 系统概述</h2>
            </div>
            <div class="api-body">
                <p class="api-description">
                    本系统提供完整的TikTok商品数据爬取解决方案，支持从TikTok商品页面提取基础信息，
                    通过Shoplus API获取详细销售数据，并提供视频数据获取功能。
                </p>
                <h4>🎯 核心功能</h4>
                <ul>
                    <li>智能爬虫：自动处理TikTok App弹窗和滑块验证</li>
                    <li>商品信息提取：获取商品标题、价格、销量等核心数据</li>
                    <li>Shoplus集成：获取详细的销售数据和市场分析</li>
                    <li>视频数据获取：提取相关推广视频信息</li>
                    <li>完整流程：一键完成从链接到数据库的全流程操作</li>
                </ul>
                <h4>🏗️ 技术架构</h4>
                <ul>
                    <li>后端：Node.js + Koa + Sequelize</li>
                    <li>数据库：MySQL</li>
                    <li>爬虫：Puppeteer + Stealth插件</li>
                    <li>API集成：Axios + Cheerio</li>
                </ul>
                <h4>📡 服务端口</h4>
                <p>默认端口：<code>3000</code></p>
                <p>访问地址：<code>http://localhost:3000</code></p>
            </div>
        </div>

        <!-- 配置管理接口 -->
        <div id="auth" class="api-section">
            <div class="api-header">
                <h2 class="api-title">🔐 认证配置接口</h2>
            </div>
            <div class="api-body">
                <p class="api-description">
                    系统支持动态配置管理，可以在运行时设置和管理authToken，无需重启服务。
                </p>
            </div>
        </div>

        <!-- 设置AuthToken -->
        <div class="api-section">
            <div class="api-header">
                <span class="api-method method-post">POST</span>
                <div class="api-url">/api/config/auth-token</div>
                <h3 class="api-title">设置认证Token</h3>
            </div>
            <div class="api-body">
                <p class="api-description">设置系统的认证Token，用于Shoplus API调用。</p>
                
                <h4>📝 请求参数</h4>
                <table class="params-table">
                    <thead>
                        <tr>
                            <th>参数名</th>
                            <th>类型</th>
                            <th>必需</th>
                            <th>说明</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>name</td>
                            <td>string</td>
                            <td class="required">是</td>
                            <td>用户名</td>
                        </tr>
                        <tr>
                            <td>expires</td>
                            <td>number</td>
                            <td class="required">是</td>
                            <td>过期时间（毫秒级时间戳）</td>
                        </tr>
                        <tr>
                            <td>accessToken</td>
                            <td>string</td>
                            <td class="required">是</td>
                            <td>访问令牌</td>
                        </tr>
                    </tbody>
                </table>

                <h4>📤 请求示例</h4>
                <div class="code-block">
                    <pre>{
  "name": "13143359181",
  "expires": 1757322261597,
  "accessToken": "Bearer eyJhbGciOiJSUzI1NiIsInR...",
  "userId": 540152
}</pre>
                </div>

                <h4>✅ 成功响应</h4>
                <div class="response-example">
                    <div class="code-block">
                        <pre>{
  "success": true,
  "message": "AuthToken设置成功"
}</pre>
                    </div>
                </div>
            </div>
        </div>

        <!-- 商品管理接口 -->
        <div id="products" class="api-section">
            <div class="api-header">
                <h2 class="api-title">📦 商品管理接口</h2>
            </div>
            <div class="api-body">
                <p class="api-description">
                    商品管理相关的API接口，包括商品信息的增删改查操作。
                </p>
            </div>
        </div>

        <!-- 处理商品链接 -->
        <div class="api-section">
            <div class="api-header">
                <span class="api-method method-post">POST</span>
                <div class="api-url">/api/products</div>
                <h3 class="api-title">处理商品链接</h3>
                <span class="tag">智能爬虫</span>
            </div>
            <div class="api-body">
                <p class="api-description">通过TikTok商品链接提取基础商品信息并保存到数据库。</p>
                
                <h4>📝 请求参数</h4>
                <table class="params-table">
                    <thead>
                        <tr>
                            <th>参数名</th>
                            <th>类型</th>
                            <th>必需</th>
                            <th>说明</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>url</td>
                            <td>string</td>
                            <td class="required">是</td>
                            <td>TikTok商品页面URL</td>
                        </tr>
                    </tbody>
                </table>

                <h4>📤 请求示例</h4>
                <div class="code-block">
                    <pre>{
  "url": "https://www.tiktok.com/t/ZTYbKJRG6/"
}</pre>
                </div>

                <h4>✅ 成功响应</h4>
                <div class="response-example">
                    <div class="code-block">
                        <pre>{
  "success": true,
  "message": "商品信息获取成功",
  "data": {
    "id": "1731808168774042656",
    "productName": "SKINTIFIC 5X Ceramide Moisture Gel...",
    "createTime": "2025-01-09T08:30:45.000Z"
  }
}</pre>
                    </div>
                </div>
            </div>
        </div>

        <!-- 获取商品信息 -->
        <div class="api-section">
            <div class="api-header">
                <span class="api-method method-get">GET</span>
                <div class="api-url">/api/products/{id}</div>
                <h3 class="api-title">获取单个商品信息</h3>
            </div>
            <div class="api-body">
                <p class="api-description">根据商品ID获取详细的商品信息。</p>
                
                <h4>🛣️ 路径参数</h4>
                <table class="params-table">
                    <thead>
                        <tr>
                            <th>参数名</th>
                            <th>类型</th>
                            <th>必需</th>
                            <th>说明</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>id</td>
                            <td>string</td>
                            <td class="required">是</td>
                            <td>商品ID</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <!-- 完整流程接口 -->
        <div id="complete-flow" class="api-section">
            <div class="api-header">
                <h2 class="api-title">🔄 完整流程接口</h2>
            </div>
            <div class="api-body">
                <p class="api-description">
                    一键完成从TikTok链接到完整商品数据的全流程操作。
                </p>
            </div>
        </div>

        <!-- 完整流程 -->
        <div class="api-section">
            <div class="api-header">
                <span class="api-method method-post">POST</span>
                <div class="api-url">/api/products/complete-flow</div>
                <h3 class="api-title">完整流程处理</h3>
                <span class="tag">推荐使用</span>
            </div>
            <div class="api-body">
                <p class="api-description">一键完成：TikTok爬取 → Shoplus搜索 → 数据库保存的完整流程。</p>
                
                <h4>📝 请求参数</h4>
                <table class="params-table">
                    <thead>
                        <tr>
                            <th>参数名</th>
                            <th>类型</th>
                            <th>必需</th>
                            <th>说明</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>url</td>
                            <td>string</td>
                            <td class="required">是</td>
                            <td>TikTok商品页面URL</td>
                        </tr>
                        <tr>
                            <td>authToken</td>
                            <td>object</td>
                            <td class="optional">否</td>
                            <td>自定义认证Token</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</body>
</html>